package net.xujialiang.XTestRPA.Repository;

import net.xujialiang.XTestRPA.Entity.XRPAUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface UserRepository extends CrudRepository<XRPAUser, Integer> {
    Optional<XRPAUser> findByTtcAndUsername(String ttc, String username);
    Page<XRPAUser> findAllByTtc(String ttc, Pageable page);
    @Query("SELECT c FROM XRPAUser c WHERE c.ttc = :ttc and (:username is null or c.username = :username) and (:nickName is null"
            + " or c.nickName = :nickName)")
    Page<XRPAUser> findByTtcAndAccountAndNickName(@Param("ttc") String ttc, @Param("username") String username, @Param("nickName") String nickName, Pageable page);
    long countByTtc(String ttc);
}
